﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;

namespace LaoLuo
{
    /// <summary>
    /// linkedlist with fixed size, insertion order is preserved. element last inserted will be the first out when traversed
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class SizedLinkedList<T> : SizedCollection<T, LinkedList<T>>
    {
        /// <summary>
        /// init a <see cref="SizedLinkedList&lt;T>"/>
        /// </summary>
        /// <param name="size">fixed-size of this list</param>
        /// <param name="items">elements to fill</param>
        public SizedLinkedList(int size, params T[] items)
            :base(size, items.AsEnumerable())
        {

        }

        /// <summary>
        /// init a <see cref="SizedLinkedList&lt;T>"/>
        /// </summary>
        /// <param name="size">fixed-size of this list</param>
        /// <param name="items">elements to fill</param>
        public SizedLinkedList(int size, IEnumerable<T> items = null)
            :base(size, items)
        {
            
        }

        protected override void Append(T item)
        {
            Container.AddFirst(item);
            //_container.AddLast(item);
        }

        protected override void Truncate()
        {
            Container.RemoveLast();
            //_container.RemoveFirst();
        }

        protected override bool Reversed
        {
            get { return false; }
        }
    }
}
